package stackExercise;

import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    public MinStack(Stack stack, Stack minStack) {
        this.stack = new Stack<>();
        this.minStack = new Stack<>();
    }
    public void push(int val){
        stack.push(val);
        if(stack.empty() && minStack.empty()){
            minStack.push(val);
        }
        if(val <= minStack.peek()){
            minStack.push(val);
        }
    }
    public void pop(){
        if(!stack.empty()){
            int ret = stack.pop();
            if(ret == minStack.peek()){
                minStack.pop();
            }
        }
    }
    //获取正常栈顶元素
    public int top(){
        if(!stack.empty()){
            return stack.peek();
        }
        return -1;
    }
    //获取最小栈顶元素
    public int getMin(){
        if(!minStack.empty()){
            return minStack.peek();
        }
        return -1;
    }

    public static void main(String[] args) {

    }
}
